package com.ruoyi.energy.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.energy.domain.NyTransformerAccount;
import com.ruoyi.energy.service.INyTransformerAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 变压器部件Controller
 *
 * @author cjie
 * @date 2021-09-26
 */
@Api(tags = " 变压器部件")
@RestController
@RequestMapping("/nyTransformerAccount")
public class NyTransformerAccountController extends BaseController {
    @Autowired
    private INyTransformerAccountService nyTransformerAccountService;

    /**
     * 负荷、容量，负荷是监控结果、容量是审批负荷
     * 查询变压器部件列表，查询变压器列表，添加类型：变压器、空开、其他部件
     */
    @ApiOperation(value="查询变压器部件列表", notes="查询变压器部件列表")
    @PreAuthorize(hasPermi = "energy:nyTransformerAccount:list")
    @GetMapping("/list")
    public TableDataInfo list(NyTransformerAccount nyTransformerAccount) {
        startPage();
        List<NyTransformerAccount> list = nyTransformerAccountService.selectNyTransformerAccountList(nyTransformerAccount);
        return getDataTable(list);
    }

    /**
     * 获取菜单下拉树列表
     */
    @GetMapping("/treeselect")
    public AjaxResult treeselect(NyTransformerAccount nyTransformerAccount)
    {
        List<NyTransformerAccount> list = nyTransformerAccountService.selectNyTransformerAccountList(nyTransformerAccount);
        return AjaxResult.success(nyTransformerAccountService.buildTransformerTreeSelect(list));
    }

    /**
     * 导出变压器部件列表
     */
    @ApiOperation(value="导出变压器部件列表", notes="导出变压器部件列表")
    @PreAuthorize(hasPermi = "energy:nyTransformerAccount:export")
    @Log(title = "变压器部件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NyTransformerAccount nyTransformerAccount) throws IOException {
        List<NyTransformerAccount> list = nyTransformerAccountService.selectNyTransformerAccountList(nyTransformerAccount);
        ExcelUtil<NyTransformerAccount> util = new ExcelUtil<NyTransformerAccount>(NyTransformerAccount.class);
        util.exportExcel(response, list, "变压器部件数据");
    }
    /**
     * 获取变压器部件详细信息
     */
    @ApiOperation(value="获取变压器部件详细信息", notes="获取变压器部件详细信息")
    @PreAuthorize(hasPermi = "energy:nyTransformerAccount:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(nyTransformerAccountService.selectNyTransformerAccountById(id));
    }

    /**
     * 新增变压器部件
     */
    @ApiOperation(value="新增变压器部件", notes="新增变压器部件")
    @PreAuthorize(hasPermi = "energy:nyTransformerAccount:add")
    @Log(title = "变压器部件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NyTransformerAccount nyTransformerAccount) {
        return toAjax(nyTransformerAccountService.insertNyTransformerAccount(nyTransformerAccount));
    }

    /**
     * 修改变压器部件
     */
    @ApiOperation(value="修改变压器部件", notes="修改变压器部件")
    @PreAuthorize(hasPermi = "energy:nyTransformerAccount:edit")
    @Log(title = "变压器部件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NyTransformerAccount nyTransformerAccount) {
        return toAjax(nyTransformerAccountService.updateNyTransformerAccount(nyTransformerAccount));
    }

    /**
     * 删除变压器部件
     */
    @ApiOperation(value="删除变压器部件", notes="删除变压器部件")
    @ApiImplicitParam(name = "ids", value = "变压器部件ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "energy:nyTransformerAccount:remove")
    @Log(title = "变压器部件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(nyTransformerAccountService.deleteNyTransformerAccountByIds(ids));
    }
}
